package com.yangtzeu.jwc.activity;

import android.os.Bundle;
import android.os.Message;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.yangtzeu.jwc.business.AppBusiness;
import com.yangtzeu.jwc.business.MCallBack;
import com.yangtzeu.jwc.domain.MyJson;
import com.zhangdi.jwc.R;
import com.zjsx.lib.utils.T;

public class FeedbackActivity extends BaseActivity {

EditText et_input_area;
TextView tv_limit_area;
Button submit_suggestion;
int limit = 200;

@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
}

@Override
public void setView() {
	setContentView(R.layout.activity_feedback);
}

@Override
public void initData() {

}

@Override
public void initActionBar() {
	setSimpleActionBar("返回", "", "反馈", "");
}

@Override
public void initView() {
	et_input_area = (EditText) findViewById(R.id.et_input_area);
	submit_suggestion = (Button) findViewById(R.id.submit_suggestion);
	tv_limit_area = (TextView) findViewById(R.id.tv_limit_area);
	tv_limit_area.setText(et_input_area.length() + "/" + limit);
}

@Override
public void initAdapter() {
	// TODO Auto-generated method stub
	super.initAdapter();
}

@Override
public void initListener() {
	super.initListener();
	submit_suggestion.setOnClickListener(this);
	et_input_area.addTextChangedListener(new TextWatcher() {

		@Override
		public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
			// TODO Auto-generated method stub
			if (et_input_area.length() > limit) {
				et_input_area.setText(arg0.subSequence(0, arg0.length() - 1));
				et_input_area.setSelection(et_input_area.length());
			} else {
				tv_limit_area.setText(et_input_area.length() + "/" + limit);
			}
		}

		@Override
		public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
			// TODO Auto-generated method stub
		}

		@Override
		public void afterTextChanged(Editable arg0) {
			// TODO Auto-generated method stub

		}
	});
	// InputUtil.KeyBoard(et_input_area, "open");
}


public final int CLOSE = 0;
@Override
public void handleMsg(Message msg) {
    // TODO Auto-generated method stub
    super.handleMsg(msg);
    if(msg.what == 0){
	this.finish();
    }
}

@Override
public void onClick(View v) {
	super.onClick(v);
	switch (v.getId()) {
	case R.id.submit_suggestion:
		String content = et_input_area.getText().toString() + "";
		if ("".equals(content.trim())) {
			T.showShort(this, "反馈的信息不能为空哦^_^！");
		} else {
			submitSuggestion(content);
		}
		break;
	}
}

public void submitSuggestion(String content) {
    	submit_suggestion.setEnabled(false);
	AppBusiness ab = new AppBusiness(this);
	String number = "";
	if(MainActivity.student != null){
	    number = MainActivity.student.getSno();
	}
	ab.feedBack(number, content, new MCallBack(){});
	T.showShort(FeedbackActivity.this, "反馈成功，谢谢您的支持^_^！！");
	handler.sendEmptyMessageDelayed(CLOSE, 1500);
}

}
